﻿
namespace DAPNet
{
    public class ClickDetection
    {
        private bool[] detections;


        public ClickDetection(int count)
        {
            this.detections = new bool[count];
        }

        public int Count
        {
            get 
            { 
                return detections.Length;
            }
        }

        public bool this[int index]
        {
            get 
            { 
                return detections[index]; 
            }
            set 
            { 
                detections[index] = value; 
            }
        }

        public int GetNumClicks()
        {
            return GetNumClicks(0, Count - 1);
        }

        public int GetNumClicks(int startIndex, int endIndex)
        {
            int numClicks = 0;
            bool previousDetection = false;
            for (int i = startIndex; i <= endIndex; i++)
            {
                if (!previousDetection && detections[i])
                {
                    numClicks++;
                }
                previousDetection = detections[i];
            }
            return numClicks;
        }

        public int GetNumDetections(bool isPositive)
        {
            return GetNumDetections(isPositive, 0, Count - 1);
        }

        public int GetNumDetections(bool isPositive, int startIndex, int endIndex)
        {
            int numDetections = 0;
            for (int i = startIndex; i <= endIndex; i++)
            {
                if (detections[i] == isPositive)
                {
                    numDetections++;
                }
            }
            return numDetections;
        }
    }
}
